home *** CD-ROM | disk | FTP | other *** search
-
- ; -------------------------------------------------------------
- ; Simple file-reading example, with crude string parsing...
- ; -------------------------------------------------------------
-
- ; We'll just highlight the first occurrence of 'Blitz' in each
- ; line of the text file...
-
- Graphics 640, 480
-
- Color 150, 150, 200
- Text 0, 12, "Reading text from 'test.txt'..."
-
- ; -------------------------------------------------------------
- ; Attempt to read the file, storing the handle as 'info'...
- ; -------------------------------------------------------------
-
- info = ReadFile ("test.txt")
-
-
- ; -------------------------------------------------------------
- ; If the handle is valid (non-zero), process the file...
- ; -------------------------------------------------------------
-
- If info
-
- ; ---------------------------------------------------------
- ; y is the y-position of the text being printed...
- ; ---------------------------------------------------------
-
- y = 24
-
- ; ---------------------------------------------------------
- ; Repeat the line-parsing until end-of-file is reached...
- ; ---------------------------------------------------------
-
- Repeat
-
- ; -----------------------------------------------------
- ; Store a line from the file in a$...
- ; -----------------------------------------------------
-
- a$ = ReadLine (info)
-
- ; -----------------------------------------------------
- ; Print the whole string in yellow...
- ; -----------------------------------------------------
-
- Color 255, 255, 100
- Text 0, y, a$
-
- ; -----------------------------------------------------
- ; Find 'Blitz', and store the (string) position...
- ; -----------------------------------------------------
-
- pos = Instr (a$, "Blitz")
-
- ; -----------------------------------------------------
- ; If we found a match...
- ; -----------------------------------------------------
-
- If pos
-
- ; -------------------------------------------------
- ; Find the x-position to print Blitz in red...
- ; -------------------------------------------------
-
- x = StringWidth (Left (a$, pos - 1))
- Color 255, 0, 0
- Text x, y, "Blitz"
-
- EndIf
-
- ; -----------------------------------------------------
- ; Increase the text y-position for the next line...
- ; -----------------------------------------------------
-
- y = y + 12
-
-
- ; ---------------------------------------------------------
- ; Repeat above until the next line is true (end-of-file)...
- ; ---------------------------------------------------------
-
- Until Eof (info)
-
- ; ---------------------------------------------------------
- ; Close the file (important!)...
- ; ---------------------------------------------------------
-
- CloseFile info
-
- Else
-
- ; ---------------------------------------------------------
- ; If the file handle was invalid (zero)...
- ; ---------------------------------------------------------
-
- RuntimeError "Failed to read test.txt! Aborting..."
-
- EndIf
-
- ; -------------------------------------------------------------
- ; Wait for mouseclick, then quit...
- ; -------------------------------------------------------------
-
- MouseWait
- End
-